import { Controller, Get, Post, Body, Param, ParseIntPipe, UseGuards, UseInterceptors, ParseUUIDPipe } from '@nestjs/common';
import { UserService } from './user.service'
import { AuthGuard } from 'src/guard/auth.guard'
import { LoggingInterceptor } from 'src/interceptors/logging.interceptor'
import { CreateUserDto } from './dto/create.user.dto'
import { NestLogService } from 'ldx-nest-log'
import { ApiTags, ApiCreatedResponse, ApiOperation } from '@nestjs/swagger'
//控制器中使用守卫
// @UseGuards(AuthGuard)
@ApiTags('用户')
@Controller('user')
//控制器中使用拦截器
// @UseInterceptors(LoggingInterceptor)
export class UserController {
  constructor(
    private readonly userService: UserService,
    private readonly Logger: NestLogService
  ) { }
  // 接口中使用守卫
  @UseGuards(AuthGuard)
  @Get('/userById/:id')
  //接口中使用拦截器
  @UseInterceptors(LoggingInterceptor)
  async userById(
    @Param('id', new ParseIntPipe()) id: number
  ) {
    console.log('id---', id);
    this.Logger.log('id');
    return await this.userService.userById(id)
  }

  @ApiOperation({
    summary: '创建用户',
    description: '创建新用户，用户名和密码必填'
  })
  @ApiCreatedResponse({
    type: CreateUserDto,
    description: '创建用户用户DTO'
  })
  @Post('/createUser')
  async create(
    @Body() data: CreateUserDto
  ) {
    return this.userService.createUser(data)
  }
}
